package homework;

public class SavingsAccount extends BankAccount{
    private int count = 3; // 每月3次存款取款免手续费的机会
    private double rate = 0.01; // 利率

    //每月3次免手续费的存款或取款，在earnMonthlyInterest方法中重置交易计数
    public void earnMonthlyInterest() {
        //每个月月初，统计上个月的利息，同时将count=3
        count = 3;
        super.deposit(getBalance() * rate);
    }

    @Override
    public void deposit(double amount) { // 存款
        //判断是否还可以免手续费
        if(count > 0) {
            super.deposit(amount);
            count--;
        } else {
            super.deposit(amount - 1); // 1块钱转入银行
        }
    }

    @Override
    public void withdraw(double amount) { // 取款
        if(count > 0) {
            super.withdraw(amount);
            count--;
        } else {
            super.withdraw(amount + 1);// 1块钱转入银行
        }
    }

    public SavingsAccount(double initialBalance) {
        super(initialBalance);
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public double getRate() {
        return rate;
    }

    public void setRate(double rate) {
        this.rate = rate;
    }
}
